package com.edu.project.test.presenter;

import android.util.Log;

import com.edu.project.bean.Weather;
import com.edu.project.test.model.WeatherModel;
import com.edu.project.test.view.TestView;

/**
 * Created by sheng on 2016/11/8.
 */
public class WeatherPresenter implements TestPrensenter<Weather> {

    private TestView mView;
    private WeatherModel weatherModel;

    public WeatherPresenter(TestView mView) {
        this.mView = mView;
        weatherModel = new WeatherModel(this);
    }

    public void loadWeatherData() {
        Log.e("Mvp ----> ","2");
        weatherModel.loadData();
    }


    public void login() {
        weatherModel.login(mView.getName(),mView.getPassword());

    }

    @Override
    public void getLoginResult(String rsult) {
        mView.loginResult(rsult);
    }

    @Override
    public void loadDataSuccess(Weather weather) {
        Log.e("Mvp ----> ","4");
        mView.loadWeatherData(weather);
    }

    @Override
    public void loadDataFailure(Throwable e) {
        mView.onResultError(e);
    }

    public void detachView() {
        if (mView != null) {
            this.mView = null;
        }
    }
}
